package com.katze.boot.web.controller;

import com.katze.boot.common.domain.GlobalConstant;
import com.katze.boot.common.exception.BusinessException;
import com.katze.boot.plugins.shiro.annotations.RestControllerMapping;
import com.katze.boot.plugins.shiro.annotations.RestRequestMapping;
import com.katze.common.Message;
import com.katze.common.http.Requester;

@RestControllerMapping("movie")
public class MovieController {

    @RestRequestMapping(value = "hot")
    public Message getMovieHot() throws BusinessException {
        try {
//            String data = HttpUtils.sendSSLPost(GlobalConstant.TIME_MOVIE_HOT_URL, "locationId=328");
            String data = Requester.getInstance().init(GlobalConstant.TIME_MOVIE_HOT_URL + "?locationId=328").send();
            return Message.ok().data(data);
        } catch (Exception e) {
            throw new BusinessException("获取热映影片信息失败", e);
        }
    }

    @RestRequestMapping(value = "coming")
    public Message getMovieComing() throws BusinessException {
        try {
//            String data = HttpUtils.sendSSLPost(GlobalConstant.TIME_MOVIE_COMING_URL, "locationId=328");
            String data = Requester.getInstance().init(GlobalConstant.TIME_MOVIE_COMING_URL + "?locationId=328").send();
            return Message.ok().data(data);
        } catch (Exception e) {
            throw new BusinessException("获取即将上映影片信息失败", e);
        }
    }

    @RestRequestMapping(value = "detail")
    public Message getDetail(String id) throws BusinessException {
        try {
//            String data = HttpUtils.sendSSLPost(GlobalConstant.TIME_MOVIE_DETAIL_URL, "locationId=328&movieId=" + id);
            String data = Requester.getInstance().init(GlobalConstant.TIME_MOVIE_DETAIL_URL + "?locationId=328&movieId=" + id).send();
            return Message.ok().data(data);
        } catch (Exception e) {
            throw new BusinessException("获取影片详情失败", e);
        }
    }

    @RestRequestMapping("comments")
    public Message getComments(String id) throws BusinessException {
        try {
//            String data = HttpUtils.sendSSLPost(GlobalConstant.TIME_MOVIE_COMMENTS_URL, "movieId=" + id);
            String data = Requester.getInstance().init(GlobalConstant.TIME_MOVIE_COMMENTS_URL + "?movieId=" + id).send();
            return Message.ok().data(data);
        } catch (Exception e) {
            throw new BusinessException("获取影片评论失败", e);
        }
    }
}
